<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.*,com.irdstudio.apicenter.console.dm.AppDuty" %>
<%@ include file="/page/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
 <%@ include file="/adapter/adapter-easyui.jsp" %> 
<%@ include file="/adapter/adapter-bootstrap.jsp" %>
<link href="${pageContext.request.contextPath}/frontframe/easyui/themes/easyui-extend.css" rel="stylesheet" type="text/css"/>
<%
List<AppDuty>  roleSelectedList=new ArrayList<AppDuty>();
List<AppDuty>  roleNoSelectedList=new ArrayList<AppDuty>();
roleSelectedList=(List<AppDuty>)request.getAttribute("dtListAready");
roleNoSelectedList=(List<AppDuty>)request.getAttribute("dtListNotYet");
%>


<script type="text/javascript">
var selectedOld = new Array();
var unselectedOld = new Array();
var selectedNew =new Array();

function preparedata()
{
//prepare data for select[roleno]
<%for(int i=0;i<roleSelectedList.size();i++ )
{
%>var dutynoOption<%=i%>=new Option();
dutynoOption<%=i%>.value="<%=(String)(roleSelectedList.get(i)).getAppDutyId()%>";

dutynoOption<%=i%>.text="<%=(String)(roleSelectedList.get(i)).getAppDutyName()%>";
document.form1.dutyno.options[<%=i%>]=dutynoOption<%=i%>;
selectedOld[<%=i%>]="<%=(String)(roleSelectedList.get(i)).getAppDutyId()%>";
<%}%>


//prepaer data for select[]
<%for(int i=0;i<roleNoSelectedList.size();i++ )
{
%>var unselectOption<%=i%>=new Option();
unselectOption<%=i%>.value="<%=(String)(roleNoSelectedList.get(i)).getAppDutyId()%>";

unselectOption<%=i%>.text="<%=(String)(roleNoSelectedList.get(i)).getAppDutyName()%>";
document.form1.unselectrole.options[<%=i%>]=unselectOption<%=i%>;
unselectedOld[<%=i%>]="<%=(String)(roleNoSelectedList.get(i)).getAppDutyId()%>";
<%}%>

};




function move(side)
{
	var temp1 = new Array();
	var temp2 = new Array();
	var tempa = new Array();
	var tempb = new Array();
	var current1 = 0;
	var current2 = 0;
	var y=0;
	var attribute1="",attribute2="";

	//assign what select attribute treat as attribute1 and attribute2
	if (side == "in")
	{
		attribute1 = document.form1.dutyno;
		attribute2 = document.form1.unselectrole;
	}
	else
	{
		attribute1 = document.form1.unselectrole;
		attribute2 = document.form1.dutyno;
	}

	//fill an array with old values
	for (var i = 0; i < attribute2.length; i++)
	{
		y=current1++
		temp1[y] = attribute2.options[i].value;
		tempa[y] = attribute2.options[i].text;
	}
	
	//assign new values to arrays
	for (var i = 0; i < attribute1.length; i++)
	{
		if ( attribute1.options[i].selected )
		{
			y=current1++
			temp1[y] = attribute1.options[i].value;
			tempa[y] = attribute1.options[i].text;
		}
		else
		{
			y=current2++
			temp2[y] = attribute1.options[i].value;
			tempb[y] = attribute1.options[i].text;
		}
	}

	//generating new options
	for (var i = 0; i < temp1.length; i++)
	{
		attribute2.options[i] = new Option();
		attribute2.options[i].value = temp1[i];
		attribute2.options[i].text =  tempa[i];
	}

	//generating new options
	for (var i=temp2.length; i<attribute1.length; i++)
	{
		attribute1.options[i] = null;
	}
	attribute1.length = temp2.length;
	if (temp2.length>0)
	{
		for (var i = 0; i < temp2.length; i++)
		{
			attribute1.options[i] = new Option();
			attribute1.options[i].value = temp2[i];
			attribute1.options[i].text =  tempb[i];
		}
	}
	//document.form2.roleno.value="";
	//document.form2.state.value="";
	//roleno._setValue("");
	//state._setValue("");
}

function  see(){
	var str="";
	var attribute=document.form1.dutyno.options;
		for(var j=0;j<attribute.length;j++)
		{
           if(j==0){
				str=attribute[j].value;	   
           }else{
				str=str+","+attribute[j].value;   
           }		
		};
		
	
	    $.ajax({
	        url:"${ctx}/appUser/saveUserDuty?dutyStr="+str+"&appid=${appId} &userid=${userid}",
	        type: "POST",      
	        dataType:"json",
	        //data: str_data,
	        async: false,
	        success: function(data) {
	        	if(data.flag>0){
		            alert("保存成功！");	
		            //window.location.reload();
	        	}
	/* 	          $.each(data, function(index, element) {
	             window.location.reload();
	          }); */
	        },
	        error: function() {
	          alert("error");
	        }
	      });
	
}


function  goBack(){
	window.history.back(-2);
}
</script>
</head>
<body  onload="preparedata();">
<!--      <div class="panel panel-default">
	   <div class="panel-heading">
	      <h3 class="panel-title">
	                                   修改用户信息
	      </h3>
	   </div>
	   <div class="panel-body"> -->
	       <!-- 开始 -->
	       <form name="form1" isLayoutContent="false" action="addroletouser" method="POST">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr>
		<td width="45%" align="center" valign="top">
			<div align="left"></div>
			<div id="p" class="easyui-panel" title="已授岗位">
<!-- 			<fieldset><legend align="center"><span class="titletext">已授岗位</span></legend>
 -->				<table width="89%" border="0" cellspacing="0" cellpadding="0">
					<tr>
						<td><span class="tdtext"><span class="titletext">岗位名称:</span></span></td>
					</tr>
					<tr>
						<td align="center"><br>
							<select name="dutyno" multiple size="15" style="width:250px"
								onDblclick="move('in');">
							</select>
							<br>
							<br>
						</td>
					</tr>
				</table>
<!-- 			</fieldset>
 -->	
 </div>
 	</td>
		<td width="10%" align="center"  style="z-index: auto;text-align: center;vertical-align:middle;padding: 15px;">
			<table width="100%" border="0" cellspacing="0" cellpadding="0">
				<tr>
					<td align="center">
						<span class="lightgrayinput"><span class="even">
							<button  type="button" name="save2" onclick="move('in');">>>></button>
						</span></span>
						<br>
						<span class="lightgrayinput"><span class="even">
							<button  type="button" name="save22" onclick="move('out');"><<<</button>
						</span></span>
					</td>
				</tr>
			</table>
		</td>
		<td width="45%" align="center" valign="top">
			<div align="left"></div>
<!-- 			<fieldset><legend align="center"><span class="titletext">可授岗位</span></legend>
 -->				
 			<div id="p" class="easyui-panel" title="可授岗位">
 <table width="89%" border="0" cellspacing="0" cellpadding="0">
					<tr class="tdtext">
						<td><span class="tdtext"><span class="titletext">岗位名称:</span></span></td>
					</tr>
					<tr class="tdtext">
						<td align="right"><br>
							<select name="unselectrole" multiple size="15" style="width:250px" 
								onDblclick="move('out');">
							</select>
							<br>
							<br>
						</td>
					</tr>
				</table>
<!-- 			</fieldset> -->
</div>
		</td>
	</tr>
</table>
<p align="center">
<button name="seee"    type="button" onclick="see();">提交</button>
&nbsp;
<button name="return"  type="button" onclick="goBack();">返回</button>

</p>

</form>
	       
	       <!-- 结束 -->
<!-- 	   </div>
	</div> -->

</body>
</html>
